/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Xceed.Silverlight.Data
{
  public class HeaderFooterDataItem : DataItem
  {
    public HeaderFooterDataItem( object data, HeaderFooterType type )
      : base( data )
    {
      this.Type = type;
      m_isHeader = ( type == HeaderFooterType.Header );
    }

    public HeaderFooterType Type
    {
      get;
      private set;
    }

    internal bool IsHeader
    {
      get
      {
        return m_isHeader;
      }
    }

    public override int GetHashCode()
    {
      object data = this.Data;

      return ( data != null )
        ? data.GetHashCode()
        : this.Type.GetHashCode();
    }

    public override bool Equals( object obj )
    {
      HeaderFooterDataItem headerDataItem = obj as HeaderFooterDataItem;
      if( headerDataItem == null )
        return false;

      // If there is no data, we have to compare the references of DataItems. 
      // The same thing applies to GetHashCode(). This is necessary because two
      // DataItems can be empty only temporarily and must be considered different
      // for the UI (container generator).
      if( !headerDataItem.IsLoaded || !this.IsLoaded )
        return object.ReferenceEquals( headerDataItem, this );

      object myData = this.Data;
      object otherData = headerDataItem.Data;

      return ( this.Type == headerDataItem.Type )
        && object.Equals( myData, otherData );
    }

    private bool m_isHeader;

    //Empty shell for the class, to be used with Headers/Footers/Group Headers/Group Footers features.
  }
}
